package com.btex.app.treaty;

import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.MyOrderHisInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/20
 * @time 上午11:04
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class OrderHisInfoAdapter extends BaseQuickAdapter<MyOrderHisInfo.DataBean.OrdersHisBean, BaseViewHolder> {

    private String mDanwei = "";
    private String mIszhen = "";
    private String mPrice = "4";
    private String mValue = "4";
    private String mMContract_value = "1";

    public OrderHisInfoAdapter() {
        super(R.layout.item_order_hisinfo_adapter);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyOrderHisInfo.DataBean.OrdersHisBean item) {

        View view = helper.getView(R.id.item_entrust_history_view_type);
        TextView item_treaty_history_tv_entrust_name = helper.getView(R.id.item_treaty_history_tv_entrust_name);
        TextView item_treaty_tv_entrust_history_time = helper.getView(R.id.item_treaty_tv_entrust_history_time);
        TextView item_treaty_tv_entrust_history_diss = helper.getView(R.id.item_treaty_tv_entrust_history_diss);
        TextView item_treaty_tv_entrust_history_type = helper.getView(R.id.item_treaty_tv_entrust_history_type);
        TextView item_treaty_tv_entrust_history_number = helper.getView(R.id.item_treaty_tv_entrust_history_number);
        TextView item_treaty_tv_entrust_history_price = helper.getView(R.id.item_treaty_tv_entrust_history_price);
        TextView item_treaty_tv_entrust_chengjiao_history_price = helper.getView(R.id.item_treaty_tv_entrust_chengjiao_history_price);
        TextView item_treaty_tv_entrust_chengjiao_history_price_type = helper.getView(R.id.item_treaty_tv_entrust_chengjiao_history_price_type);
        TextView item_treaty_tv_entrust_history_ganggan = helper.getView(R.id.item_treaty_tv_entrust_history_ganggan);
        TextView item_treaty_tv_entrust_history_duokong = helper.getView(R.id.item_treaty_tv_entrust_history_duokong);
        TextView item_treaty_tv_entrust_history_price_type = helper.getView(R.id.item_treaty_tv_entrust_history_price_type);
        TextView item_treaty_tv_entrust_history_chengjiao_shuliang = helper.getView(R.id.item_treaty_tv_entrust_history_chengjiao_shuliang);
        TextView item_treaty_tv_entrust_history_ganggan_two = helper.getView(R.id.item_treaty_tv_entrust_history_ganggan_two);
//        新增爆仓
        TextView item_treaty_tv_entrust_history_bao_cang = helper.getView(R.id.item_treaty_tv_entrust_history_bao_cang);
//        item_treaty_tv_entrust_chengjiao_history_price.setVisibility(View.INVISIBLE);
//        item_treaty_tv_entrust_chengjiao_history_price_type.setVisibility(View.INVISIBLE);
        item_treaty_tv_entrust_chengjiao_history_price_type.setText(R.string.heyue_weituo_jiazhi);
        item_treaty_tv_entrust_history_ganggan.setVisibility(View.VISIBLE);
        item_treaty_tv_entrust_history_duokong.setVisibility(View.VISIBLE);
        item_treaty_tv_entrust_history_ganggan_two.setVisibility(View.VISIBLE);

        item_treaty_history_tv_entrust_name.setText(item.getSymbol());

        item_treaty_tv_entrust_history_price_type.setText(mContext.getString(R.string.heyue_weituo_jiage));
        item_treaty_tv_entrust_history_chengjiao_shuliang.setText(mContext.getString(R.string.heyue_weituo_shuliang_chengjiao));


        String is_adl = item.getIs_adl();

        String is_liquidation = item.getIs_liquidation();

        if (is_liquidation.equals("1")) {
            item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
            item_treaty_tv_entrust_history_bao_cang.setText(R.string.qiangzhi_pingcang);
            item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
        } else {
            item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(is_adl)) {
                if (is_adl.equals("1")) {
                    item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
                    item_treaty_tv_entrust_history_bao_cang.setText(R.string.zidong_jiancang);
                    item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.new_gray));
                } else {
                    item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);
                }
            }
        }


        if (!TextUtils.isEmpty(is_adl)) {
            if (is_adl.equals("1")) {
                item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
                item_treaty_tv_entrust_history_bao_cang.setText(R.string.zidong_jiancang);
                item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.new_gray));
            } else {

                item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);

                if (is_liquidation.equals("1")) {
                    item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
                    item_treaty_tv_entrust_history_bao_cang.setText(R.string.qiangzhi_pingcang);
                    item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
                } else {
                    item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);
                }
            }
        }


        String ctime = item.getCtime();
        String timedate = Tools.timedate(ctime);
        item_treaty_tv_entrust_history_time.setText(timedate);
        String type = item.getType();
        String price = item.getPrice();
        String is_cross = item.getIs_cross();
        String amount = item.getAmount();
        String direction = item.getDirection();


        if ("1".equals(is_cross)) {
//            item_treaty_tv_entrust_history_ganggan.setText("(" + "全仓" + ")");
            item_treaty_tv_entrust_history_ganggan.setText(item.getLeverage() + "X" + ")");
            item_treaty_tv_entrust_history_ganggan_two.setText(R.string.heyue_quancang_k);
        } else {
//            item_treaty_tv_entrust_history_ganggan.setText("(" + item.getLeverage() + "X" + ")");
            item_treaty_tv_entrust_history_ganggan.setText( item.getLeverage() + "X"+")");

            item_treaty_tv_entrust_history_ganggan_two.setText(R.string.zhucang_k);
        }


        if (mIszhen != null && mDanwei != null) {

            if (mIszhen.equals("1")) {
//                反向
                if (type.equals("limit")) {
                    String Toolsamount = Tools.round(Double.valueOf(amount), 4).toString();
                    String ToolsPrice = Tools.round(Double.valueOf(price), 4).toString();
                    double v = Double.valueOf(Toolsamount) / Double.valueOf(ToolsPrice) * Double.valueOf(mMContract_value);
                    String trim = Tools.round(v, Integer.valueOf(mValue)).toString().trim();
                    item_treaty_tv_entrust_chengjiao_history_price.setText(trim + "\t" + mDanwei);

                } else {
                    item_treaty_tv_entrust_chengjiao_history_price.setText("--");

                }

//                item_treaty_tv_entrust_chengjiao_history_price.setText( + "\t" + mDanwei);

            } else {

                if (type.equals("limit")) {
                    String Toolsamount = Tools.round(Double.valueOf(amount), 4).toString();
                    String ToolsPrice = Tools.round(Double.valueOf(price), 4).toString();

                    double v = Double.valueOf(Toolsamount) * Double.valueOf(ToolsPrice) * Double.valueOf(mMContract_value);
                    String trim = Tools.round(v, Integer.valueOf(mValue)).toString().trim();

                    item_treaty_tv_entrust_chengjiao_history_price.setText(trim + "\t" + mDanwei);

                } else {
                    item_treaty_tv_entrust_chengjiao_history_price.setText("--");

                }


            }
        } else {
            Log.i("wofepwoekfpwokef", "2");
        }


        String rest_num = item.getRest_num();
        String order_status = item.getOrder_status();
        if ("1".equals(order_status)) {
            item_treaty_tv_entrust_history_diss.setText(R.string.heyue_yi_chengjiao);
            item_treaty_tv_entrust_history_diss.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.bg_green));
        } else {
            item_treaty_tv_entrust_history_diss.setText(R.string.heyue_yi_quxiao);
            item_treaty_tv_entrust_history_diss.setTextColor(Color.parseColor("#ababab"));
        }


        if ("1".equals(direction)) {
            item_treaty_tv_entrust_history_duokong.setText(R.string.heyue_duo);
//            item_treaty_tv_entrust_history_duokong.setTextColor(MyApplication.getContextObject().getColor(R.color.bg_green));

            view.setBackgroundResource(R.color.bg_green);
            item_treaty_tv_entrust_history_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.bg_green));
            if ("limit".equals(type)) {
                item_treaty_tv_entrust_history_type.setText(R.string.heyue_xianjia);
                String trim = Tools.round(Double.valueOf(price), Integer.valueOf(mPrice)).toString().trim();
                item_treaty_tv_entrust_history_price.setText(trim);
            } else {
                item_treaty_tv_entrust_history_type.setText(R.string.heyue_shijia);
                item_treaty_tv_entrust_history_price.setText(R.string.heyue_shijia);
            }

        } else {
//            item_treaty_tv_entrust_history_duokong.setTextColor(MyApplication.getContextObject().getColor(R.color.red));
            item_treaty_tv_entrust_history_duokong.setText(R.string.heyue_kong);
            view.setBackgroundResource(R.color.red);
            item_treaty_tv_entrust_history_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
            if ("limit".equals(type)) {
                item_treaty_tv_entrust_history_type.setText(R.string.heyue_xianjia);
                String trim = Tools.round(Double.valueOf(price), Integer.valueOf(mPrice)).toString().trim();
                item_treaty_tv_entrust_history_price.setText(trim);
            } else {
                item_treaty_tv_entrust_history_type.setText(R.string.heyue_shijia);
                item_treaty_tv_entrust_history_price.setText(R.string.heyue_shijia);
            }
        }

//        double v = Double.parseDouble(amount) - Double.parseDouble(rest_num);


        item_treaty_tv_entrust_history_number.setText(amount + "/" + rest_num);


    }


    public void setDanwei(String danwei) {

        mDanwei = danwei;
    }


    public void setIszhen(String iszhen) {

        mIszhen = iszhen;
    }


    public void SetNumber(String price, String value) {
        this.mPrice = price;
        this.mValue = value;
    }

    public void setmContract_value(String mContract_value) {

        mMContract_value = mContract_value;
    }
}
